const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
		is_store:0,
		focus:false,
		is_show:false,
		config:{},
		group:{},
    store:[],
	},
	//打开载入
  onLoad: function (options) {
		app.getParam(options,(param) => {
			if(app.util().isNull(param.group_id)){
				this.setData({
					focus:true
				})
			}else{
				this.data.group_id = parseInt(param.group_id)
			}
		});
	},
	onShow:function () {
		app.loginState(rel => {
			app.appConfig((config)=>{
				this.setData({
					is_store:config.store.is_store
				})
				if(config.store.is_store == 1 && this.data.group_id > 0){
					this.apiGroup();
				}
			})
		},true)
	},
	//必须登录
	onSearch:function(e){
		if(e.detail != null){
			this.data.group_id = parseInt(e.detail)
			this.apiGroup();
		}else(
			this.data.group_id = 0
		)
	},
	//获取API
	apiGroup: function () {
		app.api().Get('api/v1/ais/gmgroup/read',{id: this.data.group_id},(result) => {
			if (result.code == 200) {
				this.setData({
					group:result.data,
					is_show:true
				})
				this.apiGroupStore();
			}else{
				this.setData({
					is_show:false
				})
			}
		})
	},
	//获取API
	apiGroupStore: function () {
		app.api().Get('api/v1/ais/gmgroup/store',{id:this.data.group_id,type:0},(result) => {
			if (result.code == 200) {
				this.setData({
					store:result.data,
				})
			}
		})
	},
	//申请入圈
	apiGroupOperate: function () {
		app.api().Get('api/v1/ais/gmgroup/add',{id:this.data.group_id},(result) => {
			app.wxAlert(result.msg,() =>{
				wx.navigateBack({
					delta:1
				})
			})
		}) 
	}
})